package com.fs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.pojo.User;
import com.fs.pojo.WhWarehouse;
import com.fs.service.UserService;
import com.fs.service.WareHouseService;
import com.fs.util.ResponseDataUtil;
import com.fs.vo.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author hyy
 * @version 1.0
 * @description: 仓库控制层访问
 * @date 2024/10/12 16:09
 */
@RestController
@RequestMapping("/reverse/warehouse")
public class WhWareHouseController {

    @Resource
    private WareHouseService wareHouseService;

    @Resource
    private UserService userService;


    @GetMapping
    public ResponseData queryWarehouse(Integer pageNum, Integer pageSize,String warehouseName, String warehouseLocation, Integer warehouseResponsible){
        WhWarehouse whWarehouse = new WhWarehouse(warehouseName, warehouseLocation, warehouseResponsible);
//
//        System.out.println("接受条件——"+whWarehouse);
        //仓库分页查询信息
        Page<WhWarehouse> whWarehousePage = wareHouseService.queryWareHouse(pageNum,pageSize,whWarehouse);
        //对应仓库负责人的查询信息
        List<User> users = userService.queryUsers(null);
        HashMap<String, Object> map = new HashMap<>();
        map.put("pages",whWarehousePage);
        map.put("respositoryPerson",users);
        return whWarehousePage!=null?ResponseDataUtil.buildOk(map):ResponseDataUtil.buildFail(null);
    }

    /**
     * 查询仓库表单
     * @param  id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseData queryWarehouse(@PathVariable Integer id){
        WhWarehouse whWarehousePage = wareHouseService.queryWareHouseById(id);
        return whWarehousePage!=null?ResponseDataUtil.buildOk(whWarehousePage):ResponseDataUtil.buildFail(null);
    }

    /**
     * 删除仓库
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseData delWarehouse(@PathVariable Integer id){
        Integer result = wareHouseService.delWareHouse(id);
        return result!=0?ResponseDataUtil.buildOk("200","删除成功"):ResponseDataUtil.buildFail(null);
    }

    /**
     * 新增仓库
     * @param whWarehouse
     * @return
     */
    @PostMapping
    public ResponseData addWareHouse(@RequestBody WhWarehouse whWarehouse){
        Integer result = wareHouseService.addWareHouse(whWarehouse);
        return result!=0?ResponseDataUtil.buildOk("200","新增成功"):ResponseDataUtil.buildFail(null);
    }

    /**
     * 新增仓库
     * @param whWarehouse
     * @return
     */
    @PostMapping("update")
    public ResponseData updateWareHouse(@RequestBody WhWarehouse whWarehouse){
        Integer result = wareHouseService.updateWareHouse(whWarehouse);
        return result!=0?ResponseDataUtil.buildOk("200","修改成功"):ResponseDataUtil.buildFail(null);
    }
}
